library(splines)
library(stats)
library(PLCE)
bs.me<-function(x) PLCE:::bs.me(x)[,-1]

options(device="quartz")

n<-200

x<-seq(0:(n))/n


x.spline<-bs.me(x)

pdf("SuppMaterialsFig2_Ratkovic.pdf",h=5.8,w=8)


par(mar = c(3, 3.4, 1, 1), # Dist' from plot to side of page
    mgp = c(2, 0.4, 0), # Dist' plot to label
    las = 1, # Rotate y-axis text
    tck = -.01, # Reduce tick length
    xaxs = "i", yaxs = "i", # Remove plot padding
    oma =c(0,0,0,0))



plot(x,bs.me(x)[,1],type="n",ylim=range(x.spline),xlab="",ylab="")
mtext(side=2,font=2,expression(paste("Transformed Covariate, ",phi[j](x[i]))),cex=1.3,line=1.9, las=0)
mtext(side=1,font=2,expression(paste("Original Covariate, ",x[i])),cex=1.3,line=1.9, las=0)

rect(par("usr")[1],par("usr")[3],par("usr")[2],par("usr")[4],col = "gray90")
abline(v=(1:9)/5,col="white")
abline(h=(1:50)/4,col="white")

gg_color <- function(n,alpha0=1) {
  hues = seq(15, 375, length = n + 1)
  hcl(h = hues, l = 65, c = 100,alpha=alpha0)[1:n]
}

for(i in 1:ncol(x.spline)){
  lines(x,x.spline[,i],col=gg_color(ncol(x.spline))[i],lwd=3)
}

dev.off()
